package com.dingceng.demo.base

import android.content.Context
import android.content.res.Resources
import android.util.TypedValue
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.dingceng.demo.base.glide.GlideSmartRoundedCornersTransform

/**
 * 常用拓展函数
 */
val Float.dp
    get() = TypedValue.applyDimension(
        TypedValue.COMPLEX_UNIT_DIP,
        this,
        Resources.getSystem().displayMetrics
    )

val Int.dp
    get() = TypedValue.applyDimension(
        TypedValue.COMPLEX_UNIT_DIP,
        this.toFloat(),
        Resources.getSystem().displayMetrics
    ).toInt()

val Context.screenWidth
    get() = resources.displayMetrics.widthPixels

val Context.screenHeight
    get() = resources.displayMetrics.heightPixels

fun ImageView.show(url: String) {
    this.show(url,0.dp)
}

fun ImageView.show(url: String,radius:Int) {
    Glide.with(BaseApplication.getIns())
        .load(url)
        .transform(CenterCrop(), GlideSmartRoundedCornersTransform(radius, 0, GlideSmartRoundedCornersTransform.CornerType.ALL))
        .into(this)
}
